#include<iostream>
#include<queue>
using namespace std;
const int N = 1e5 + 10;
struct node
{
	int l, r;
}s[N];
int cmp(node a, node b)
{
	return a.l < b.l;
}
int n;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		s[i] = { a,b };
	}
	sort(s, s + n, cmp);
	priority_queue<int, vector<int>, greater<int> >heap;
	for (int i = 0; i < n; i++) {
		auto t = s[i];
		if (heap.size() == 0 || heap.top() >= t.l) {
			heap.push(t.r);
		}
		else {
			heap.pop();
			heap.push(t.r);
		}
	}
	cout << heap.size() << endl;
	/*int n = heap.size();
	for (int i = 0; i < n; i++) {
		cout << heap.top() << endl;
		heap.pop();
	}*/
	return 0;
}